var xmlhttp;
if (window.XMLHttpRequest) {
	// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp = new XMLHttpRequest();
} else {
	// code for IE6, IE5
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

document.onkeydown = function(event) {
	e = event ? event : (window.event ? window.event : null);
	if (e.keyCode == 13) {
		// alert('回车检测到了');
		if (document.getElementById('login_div').style.display != "none") {
			document.getElementById('loginbutton').click();
		}
	}
}

/*
 * 点击 标签切换
 */
function tabClick(tabId) {
	if (tabId == "tabsName-1") {
		selectTabs("#tabs-1");
	}
	if (tabId == "tabsName-2") {
		selectTabs("#tabs-2");
	}
	if (tabId == "tabsName-3") {
		selectTabs("#tabs-3");
	}
	if (tabId == "tabsName-4") {
		selectTabs("#tabs-4");
	}
}

/*
 * 登录
 */
function login() {
	// alert("login");
	validateResult = validate();
	if (validateResult == '1') {
		alert("请输入验证码！");
		return false;
	} else if (validateResult == '2') {
		alert("验证码输入错误！");
		return false;
	} else if (validateResult == '3') {

	}
	var str = "";
	var elem = document.forms['loginForm'].elements;
	for ( var i = 0; i < elem.length; i++) {
		if (i != 0){
			str += "&";
		}
		str += elem[i].name + "=" + elem[i].value;
	}

	var calc = document.getElementById('Calc');
	var result = calc.POST("http://api.cntv.cn/client/auth", str);
	if (result == 200) {
		// alert(calc.GetResponse());
		// var json = eval('(' + calc.GetResponse() + ')');
		// var json = calc.GetResponse().parseJSON();
		var myJson = calc.GetResponse();
		var json = eval("(" + myJson + ")");
		// alert("login:ret:" + json.ret);
		if (json.ret == "succ") {
			// alert("login:ret:" + json.username);
			initPage();
		} else {
			alert(json.msg);
		}
	}

}

/*
 * 退出
 */
function loginout() {
	window.location.href = "http://api.cntv.cn/client/logout?t=" + new Date().getTime();
	var str = "";
	xmlhttp.onreadystatechange = loginoutCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/logout", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 退出回调
 */
function loginoutCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//query = location.search;
		//location.reload();
		//window.open("mainpage.html");
		 window.location.href = "mainpage.html";
	}
}

/*
 * 单片添加
 */
function add() {
	var str = "";
	var elem = document.forms['addForm'].elements;
	var cover = '';
	var sendtype = '';
	for ( var i = 0; i < elem.length; i++) {
		if ( elem[i].type == "checkbox" ) {
			if( elem[i].name == 'cover' ){
				if(elem[i].checked == true){
					cover +=","+elem[i].value;
				}
			}else if( elem[i].name == 'sendtype' ){
				if(elem[i].checked == true){
					sendtype ='1';
				}
			}

		}else if( elem[i].name != '' && elem[i].value != '' ){
			if (i != 0){
				str += "&";
			}
			str += elem[i].name + "=" + elem[i].value;
		}
		if( elem[i].name == 'title' ){
			var title = elem[i].value;
		}
		if( elem[i].name == 'tag' ){
			var tag = elem[i].value;
		}
		if( elem[i].name == 'intro' ){
			var intro = elem[i].value;
		}
		if( elem[i].name == 'album_id' ){
			var album_id = elem[i].value;
		}
		if( elem[i].name == 'special_id' ){
			var special_id = elem[i].value;
		}
		
		
		if( elem[i].name == 'cat_id' ){
			var cat_id = elem[i].value;
		}
		if( elem[i].name == 'repeat_id' ){
			var repeat_id = elem[i].value;
		}
     if( elem[i].name == 'partner_id' ){
			var partner_id = elem[i].value;
		}
     

	}
	if(title == ''){alert("标题不能为空！");return;}
	if(tag == ''){alert("标签不能为空！");return;}
	if(intro == ''){alert("简介不能为空！");return;}
	if(cat_id == '' ||cat_id ==0){alert("分类不能为空！");return;}
	if(repeat_id ==''){alert("马甲不能为空！");return;}
	if(partner_id == ''){alert("合作伙伴不能为空！");return;}
	/*
	if( (isNaN(special_id) || special_id =='') || ( isNaN(album_id)  || album_id =='' )  ){
		alert("请填写正确的专辑id和专题id！");
		return;
	}
	*/
	cover = cover.substring(1);
	str +="&cover="+cover+"&sendtype="+sendtype;
//	alert(str);

	var calc = document.getElementById('Calc');
	var result = calc.POST("http://api.cntv.cn/client/add", str);
	 // alert(result);
	// 返回-1是其他错误; 返回-2是C:\\WINDOWS\\system32\\drivers\\etc\\hosts不可读;
	// 返回-3是api.cntv.cn不通
	if (result == 200) {
		 // alert(calc.GetResponse());
		// var json = eval('(' + calc.GetResponse() + ')');
		// var json = calc.GetResponse().parseJSON();
		var myJson = calc.GetResponse();
		if(myJson != ""){
			var json = eval("(" + myJson + ")");
			alert(json.msg);
			location.reload();
		}else{
			alert("添加失败！");
		}

	}
	// alert("add4");

	/*
	 * xmlhttp.onreadystatechange = addCallback; xmlhttp.open("POST",
	 * "http://api.cntv.cn/client/add", false);
	 * xmlhttp.setRequestHeader("Content-Type",
	 * "application/x-www-form-urlencoded"); xmlhttp.send(str);
	 */
}

/*
 * 批量添加
 */
function batchadd() {
	//alert("batchadd01");
	var str = "";
	/* 获取选中的项 */
	var checkitem = document.getElementsByName("checkitem");
	//alert("batchadd02"+checkitem.length);
	for(var i = 0;i<checkitem.length;i++){
		//alert("batchadd03"+checkitem[i].checked);
		if (checkitem[i].checked){
			var urlObj = document.getElementById("url_" + i);
			if( typeof (urlObj) != "undefined" && urlObj != "" && urlObj != null ){
					//alert("url_" + i);
					url = document.getElementById("url_" + i).value;
					str += "&url[]=" + url + '';
			}
		}
		//alert("batchadd04");
		// title = document.getElementById("title_"+i).value;
		// alert(title);
		
		// str += "&title[]=" + title + '';
	}
	if( str !="" ){
		str = str.substring(1);
	}
	
	var elem = document.forms['batchForm'].elements;
	var sendtype = '';
	for ( var i = 0; i < elem.length; i++) {
		if ( elem[i].type == "checkbox" ) {
			if( elem[i].name == 'sendtype' ){
				if(elem[i].checked == true){
					sendtype ='1';
				}
			}

		}else if( elem[i].name != '' && elem[i].value != '' ){
			if (i != 0){
				str += "&";
			}
			str += elem[i].name + "=" + elem[i].value;
		}

	}
	str +="&sendtype="+sendtype;
	//alert(str);

	var calc = document.getElementById('Calc');
	var result = calc.POST("http://api.cntv.cn/client/batchadd", str);
	 //alert(result);
	// 返回-1是其他错误; 返回-2是C:\\WINDOWS\\system32\\drivers\\etc\\hosts不可读;
	// 返回-3是api.cntv.cn不通
	if (result == 200) {
		 //alert(calc.GetResponse());
		// var json = eval('(' + calc.GetResponse() + ')');
		// var json = calc.GetResponse().parseJSON();
		var myJson = calc.GetResponse();
		if(myJson != ""){
			var json = eval("(" + myJson + ")");
			 alert(json.msg);
			// document.getElementById('tabsName-2').click();
			//localData.setItem("Arraytitle", null);
			//localData.setItem("Arrayurl", null);
			// location.reload();
			window.location.href = "mainpage.html#tabs-2";
			//selectTabs("#tabs-2");
		}else{
			alert("添加失败！");
		}
	}

	/*
	 * xmlhttp.onreadystatechange = batchaddCallback; xmlhttp.open("POST",
	 * "http://api.cntv.cn/client/batchadd", false);
	 * xmlhttp.setRequestHeader("Content-Type",
	 * "application/x-www-form-urlencoded"); xmlhttp.send(str);
	 */
}
/*
 * 全选
 */
function checkall() {
	 // alert("checkall");
	var code_Values = document.getElementsByName("checkitem");
	for (i = 0; i < code_Values.length; i++) {
		if (code_Values[i].type == "checkbox") {
			code_Values[i].checked = true;
		}
	}
}
/*
 * 取消全选
 */
function uncheckall() {
	// alert("uncheckall");
	var code_Values = document.getElementsByName("checkitem");
	for (i = 0; i < code_Values.length; i++) {
		if (code_Values[i].type == "checkbox") {
			if(code_Values[i].checked == false){
				code_Values[i].checked = true;
			}else if(code_Values[i].checked == true){
				code_Values[i].checked = false;
			}
		}
	}
}

/*
 * 取得马甲信息
 */
function getrepeat() {

	var str = "";
	// xmlhttp.onreadystatechange = getrepeatCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getrepeat?t=" + new Date().getTime(), false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
	getrepeatCallback();
}

/*
 * 取得马甲信息回调
 */
function getrepeatCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//alert(xmlhttp.responseText);
		// initPage();
		// var json = JSON.parse(xmlhttp.responseText);
		var json = eval("(" + xmlhttp.responseText + ")");
		repeat_id_select = document.getElementById("repeat_id");
		repeat_id_select.options.length = 0;
		set_repeat_id_select = document.getElementById("set_repeat_id");
		set_repeat_id_select.options.length = 0;
		if (repeat_id_select != null) {
			repeat_id_select.options.add(new Option("选择马甲", ""));
		}
		if (set_repeat_id_select != null) {
			set_repeat_id_select.options.add(new Option("选择马甲", ""));
		}
		if (json.ret == 'succ') {
			// @TODO
			$.each(json.data, function(index, d) {
				if (repeat_id_select != null) {
					repeat_id_select.options.add(new Option(d.repeat_name,
							d.repeat_id));
				}
				if (set_repeat_id_select != null) {
					set_repeat_id_select.options.add(new Option(d.repeat_name,
							d.repeat_id));
				}
			});
		} else {
			if (repeat_id_select != null) {
				
			}
			if (set_repeat_id_select != null) {
				
			}
		}
	}
}

/*
 * 取得合作伙伴信息
 */
function getpartner() {
	var str = "";
	// xmlhttp.onreadystatechange = getpartnerCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getpartner?t=" + new Date().getTime(), false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
	getpartnerCallback();

}

/*
 * 取得合作伙伴信息回调
 */
function getpartnerCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		// var json = JSON.parse(xmlhttp.responseText);
		var json = eval("(" + xmlhttp.responseText + ")");
		partner_id_select = document.getElementById("partner_id");
		partner_id_select.options.length = 0;
		set_partner_id_select = document.getElementById("set_partner_id");
		set_partner_id_select.options.length = 0;
		if (partner_id_select != null) {
			partner_id_select.options.add(new Option("合作伙伴", ""));
		}
		if (set_partner_id_select != null) {
			set_partner_id_select.options.add(new Option("合作伙伴", ""));
		}
		if (json.ret == 'succ') {
			// @TODO
			$.each(json.data, function(index, d) {
				if (partner_id_select != null) {
					partner_id_select.options.add(new Option(d.title,
							d.pid));
				}
				if (set_partner_id_select != null) {
					set_partner_id_select.options.add(new Option(d.title,
							d.pid));
				}
			});
		} else {
			if (partner_id_select != null) {
				
			}
			if (set_partner_id_select != null) {
				
			}
		}
	}
}

/*
 * 取得分类信息
 */
function getcat() {
	var str = "";
	//xmlhttp.onreadystatechange = getcatCallback;
	xmlhttp.open("GET", "http://api.xiyou.cntv.cn/general/getcategory?pid=100&lang=zh_cn&format=json?t=" + new Date().getTime(), false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
	getcatCallback();
}
/*
 * 取得分类信息回调
 */
function getcatCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//var json = JSON.parse(xmlhttp.responseText);
		var json = eval("("+xmlhttp.responseText+")");
		partner_id_select = document.getElementById("cat_id");
		partner_id_select.options.length = 0;
		set_partner_id_select = document.getElementById("set_cat_id");
		set_partner_id_select.options.length = 0;
		if (partner_id_select != null) {
			partner_id_select.options.add(new Option("分类", "0"));
		}
		if (set_partner_id_select != null) {
			set_partner_id_select.options.add(new Option("分类", "0"));
		}
		//alert(json.status);
		if (json.status == 'success') {
			// @TODO
			$.each(json.data, function(index, d) {
				if (partner_id_select != null) {
					partner_id_select.options.add(new Option(d.name,
							d.id));
				}
				if (set_partner_id_select != null) {
					set_partner_id_select.options.add(new Option(d.name,
							d.id));
				}
			});
		} else {

		}
	}
}


/*
 * 取得视频列表
 */
function videolist(pagenum) {
	var str = "";
	if (pagenum == 0) {
		pagenum = document.getElementById("pagenum").value;
	}
	
	var status = document.getElementById("status").value;
	var str = "?status="+ status +"&format=json&page=" + pagenum + "&pagesize=20";
	
	//var str = "?format=json&page=" + pagenum + "&pagesize=20";
	select = document.getElementById("type");
	type = select.options[select.selectedIndex].value;
	keyword = encodeURIComponent(document.getElementById("keyword").value);
	// alert(keyword);
	if (type == "title") {
		str += "&title=" + keyword;
	} else if (type == "url") {
		str += "&url=" + keyword;
	}
	
    var calc = document.getElementById('Calc');
    result = calc.GET("http://api.cntv.cn/client/videolist"+str);
    // alert(result); //返回-1是其他错误;
    // 返回-2是C:\\WINDOWS\\system32\\drivers\\etc\\hosts不可读; 返回-3是api.cntv.cn不通
    if(result==200) {
    	//alert(calc.GetResponse());
    	if(calc.GetResponse() != ""){
    		var data = eval("(" + calc.GetResponse() + ")");
        	
    		if(data.ret == 'succ'){
	    		var tab = document.getElementById("videolist");
	    		var table = "<table class=\"tbl lstb\">";
	    		table += "<tr>";
	    		table += "<th>状态</th>";
	    		table += "<th>标题</th>";
	    		table += "<th>时间</th>";
	    		table += "<th>地址</th>";
	    		table += "<th>备注</th>";
	    		table += "</tr>";
	    		
	        	datalist = data.data;
	        	for(var i=0;i<datalist.length;i++){
	        		// 视频采集状态 10：待采集 15：采集中 20：已采集30：采集失败 35：送审中 40：已送审50：送审失败
	        		if (datalist[i].status == '10') {
	        			var statusName = "待采集";
	        		} else if (datalist[i].status == '15') {
	        			var statusName = "采集中";
	        		} else if (datalist[i].status == '20') {
	        			var statusName = "已采集";
	        		} else if (datalist[i].status == '30') {
	        			var statusName = "采集失败";
	        		} else if (datalist[i].status == '35') {
	        			var statusName = "送审中";
	        		} else if (datalist[i].status == '40') {
	        			var statusName = "已送审";
	        		} else if (datalist[i].status == '50') {
	        			var statusName = "送审失败";
	        		} else {
	        			var statusName = "未知";
	        		}
	
	        		table += "<tr>";
	        		table += "<td  width=\"27\">" + statusName + "</td>";
	        		table += "<td  width=\"161\">" + datalist[i].title + "</td>";
	        		table += "<td width=\"70\">" + datalist[i].add_time + "</td>";
	        		table += "<td width=\"27\"><a style=\"color:#58a300;\" href=\"" + datalist[i].url + "\" target=\"_blank\">打开</a></td>";
	        		table += "<td  width=\"90\" style=\"width:90px;word-break:break-all;\">" + datalist[i].errmsg + "</td>";
	        		table += "</tr>";
	        	}
	
	    		table += "</table>";
	    		tab.innerHTML = table;
	
	    		var listinfo = "<span id=\"listtotal\">共" + data.total + "条信息</span>";
	
	    		if (data.currentpage > 1) {
	    			var prePage = data.currentpage - 1;
	    		} else {
	    			var prePage = 1;
	    		}
	    		if (data.currentpage >= data.totalpages) {
	    			var nextPage = data.totalpages;
	    		} else {
	    			var nextPage = data.currentpage + 1;
	    		}
	    		listinfo += "<a href=\"?page=" + prePage
	    				+ "#tabs-4\" id=\"firstButton\">|<<</a>";
	    		if (data.totalpages > 5) {
	    			var hasMore = true;
	
					if( (data.currentpage % 5) == 0){
						currentBlock = ((data.currentpage / 5)-1) * 5 + 1;
					}else{
						currentBlock = Math.floor(data.currentpage / 5) * 5 + 1;
					}
	    			if ((currentBlock + 5) > data.totalpages) {
	    				var perBlock = data.totalpages + 1;
	    			} else {
	    				var perBlock = currentBlock + 5;
	    			}
	
	    			for ( var num = currentBlock; num < perBlock; num++) {
	    				if (data.currentpage == num) {
	    					listinfo += "<a href=\"?page="
	    							+ num
	    							+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
	    							+ num + "\">" + num + "</a>";
	    				} else {
	    					listinfo += "<a href=\"?page="
	    							+ num
	    							+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
	    							+ num + "\">" + num + "</a>";
	    				}
	    			}
	    		} else {
	    			var perBlock = data.totalpages;
	    			var hasMore = false;
	    			for ( var num = 1; num <= perBlock; num++) {
	    				if (data.currentpage == num) {
	    					listinfo += "<a href=\"?page="
	    							+ num
	    							+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
	    							+ num + "\">" + num + "</a>";
	    				} else {
	    					listinfo += "<a href=\"?page="
	    							+ num
	    							+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
	    							+ num + "\">" + num + "</a>";
	    				}
	    			}
	    		}
	    		if (data.currentpage >= data.totalpages) {
	    			listinfo += "<a href=\"?page=" + nextPage
	    					+ "#tabs-4\" id=\"lastButton\">>>|</a>";
	    		} else {
	    			listinfo += " ...<a href=\"?page=" + nextPage
	    					+ "#tabs-4\" id=\"lastButton\">>>|</a>";
	    		}
	
	    		var pageInfo = document.getElementById("listinfo");
	    		pageInfo.innerHTML = listinfo;
    		}else{
    			var tab = document.getElementById("videolist");
    			var table = "<table class=\"tbl lstb\">";
    			table += "<tr>";
    			table += "<th>状态</th>";
    			table += "<th>标题</th>";
    			table += "<th>时间</th>";
    			table += "<th>地址</th>";
    			table += "<th>备注</th>";
    			table += "</tr>";
    			table += "</table>";
    			tab.innerHTML = table;
    	
    			listinfo = "<span id=\"listtotal\"></span>";
    			var pageInfo = document.getElementById("listinfo");
    			pageInfo.innerHTML = listinfo;
    			
    			alert(data.msg);
    		}
    	}
    	
    	
    }
	
	/*
	// xmlhttp.onreadystatechange = getuserinfoCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/videolist"+str, false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
	videolistCallback();
	*/

}

/*
 * 取得视频列表回调
 */
function videolistCallback() {
	// alert("videolistCallback");

	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		 alert("videolistCallback:" + xmlhttp.responseText);
		// var data = JSON.parse(xmlhttp.responseText);
		var data = eval("(" + xmlhttp.responseText + ")");
		if(data.ret == 'succ'){
			var tab = document.getElementById("videolist");
			var table = "<table class=\"tbl lstb\">";
			table += "<tr>";
			table += "<th>状态</th>";
			table += "<th>标题</th>";
			table += "<th>时间</th>";
			table += "<th>地址</th>";
			table += "<th>备注</th>";
			table += "</tr>";
			/*
			$.each(data.data, function(index, d) {
				// 视频采集状态 10：待采集 15：采集中 20：已采集30：采集失败 35：送审中 40：已送审50：送审失败
				if (d.status == '10') {
					var statusName = "待采集";
				} else if (d.status == '15') {
					var statusName = "采集中";
				} else if (d.status == '20') {
					var statusName = "已采集";
				} else if (d.status == '30') {
					var statusName = "采集失败";
				} else if (d.status == '35') {
					var statusName = "送审中";
				} else if (d.status == '40') {
					var statusName = "已送审";
				} else if (d.status == '50') {
					var statusName = "送审失败";
				} else {
					var statusName = "未知";
				}
	
				table += "<tr>";
				table += "<td>" + statusName + "</td>";
				table += "<td>" + d.title + "</td>";
				table += "<td>" + d.add_time + "</td>";
				table += "<td>" + d.url + "</td>";
				table += "</tr>";
	
			})
			*/
			
	for (var one in data.data){
		for(var key in data.data[one])
		{
			//str += data.data[one][key];
			
			// 视频采集状态 10：待采集 15：采集中 20：已采集30：采集失败 35：送审中 40：已送审50：送审失败
			if (data.data[one][key].status == '10') {
				var statusName = "待采集";
			} else if (data.data[one][key].status == '15') {
				var statusName = "采集中";
			} else if (data.data[one][key].status == '20') {
				var statusName = "已采集";
			} else if (data.data[one][key].status == '30') {
				var statusName = "采集失败";
			} else if (data.data[one][key].status == '35') {
				var statusName = "送审中";
			} else if (data.data[one][key].status == '40') {
				var statusName = "已送审";
			} else if (data.data[one][key].status == '50') {
				var statusName = "送审失败";
			} else {
				var statusName = "未知";
			}
	
			table += "<tr>";
			table += "<td  width=\"27\">" + statusName + "</td>";
			table += "<td  width=\"161\">" + data.data[one][key].title + "</td>";
			table += "<td width=\"70\">" + d.add_time + "</td>";
			table += "<td width=\"27\"><a style=\"color:#58a300;\" href=\"" + d.url + "\" target=\"_blank\">打开</a></td>";
			table += "<td width=\"90\">" + d.errmsg + "</td>";
			table += "</tr>";
			
		}
	}
			
			table += "</table>";
			tab.innerHTML = table;
	
			var listinfo = "<span id=\"listtotal\">共" + data.total + "条信息</span>";
	
			if (data.currentpage > 1) {
				var prePage = data.currentpage - 1;
			} else {
				var prePage = 1;
			}
			if (data.currentpage >= data.totalpages) {
				var nextPage = data.totalpages;
			} else {
				var nextPage = data.currentpage + 1;
			}
			listinfo += "<a href=\"?page=" + prePage
					+ "#tabs-4\" id=\"firstButton\">|<<</a>";
			if (data.totalpages > 5) {
				var hasMore = true;
	
				var currentBlock = Math.floor(data.currentpage / 6) * 5 + 1;
				if ((currentBlock + 5) > data.totalpages) {
					var perBlock = data.totalpages + 1;
				} else {
					var perBlock = currentBlock + 5;
				}
	
				for ( var num = currentBlock; num < perBlock; num++) {
					if (data.currentpage == num) {
						listinfo += "<a href=\"?page="
								+ num
								+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
								+ num + "\">" + num + "</a>";
					} else {
						listinfo += "<a href=\"?page="
								+ num
								+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
								+ num + "\">" + num + "</a>";
					}
				}
			} else {
				var perBlock = data.totalpages;
				var hasMore = false;
				for ( var num = 1; num <= perBlock; num++) {
					if (data.currentpage == num) {
						listinfo += "<a href=\"?page="
								+ num
								+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
								+ num + "\">" + num + "</a>";
					} else {
						listinfo += "<a href=\"?page="
								+ num
								+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
								+ num + "\">" + num + "</a>";
					}
				}
			}
			if (data.currentpage >= data.totalpages) {
				listinfo += "<a href=\"?page=" + nextPage
						+ "#tabs-4\" id=\"lastButton\">>>|</a>";
			} else {
				listinfo += " ...<a href=\"?page=" + nextPage
						+ "#tabs-4\" id=\"lastButton\">>>|</a>";
			}
	
			var pageInfo = document.getElementById("listinfo");
			pageInfo.innerHTML = listinfo;
		}else{
			alert(data.msg);
		}

	}
}

/*
 * 取得queryString参数
 */
function GetRequest() {
	var url = location.search; // 获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for ( var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}

/**
 * 框选需要
 * 
 */
function Base64() {
	// private property
	_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	// public method for decoding
	this.decode = function(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		if( input != null){
			input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
			while (i < input.length) {
				enc1 = _keyStr.indexOf(input.charAt(i++));
				enc2 = _keyStr.indexOf(input.charAt(i++));
				enc3 = _keyStr.indexOf(input.charAt(i++));
				enc4 = _keyStr.indexOf(input.charAt(i++));
				chr1 = (enc1 << 2) | (enc2 >> 4);
				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				chr3 = ((enc3 & 3) << 6) | enc4;
				output = output + String.fromCharCode(chr1);
				if (enc3 != 64) {
					output = output + String.fromCharCode(chr2);
				}
				if (enc4 != 64) {
					output = output + String.fromCharCode(chr3);
				}
			}
			output = _utf8_decode(output);
		}
		return output;
	}

	// private method for UTF-8 decoding
	_utf8_decode = function(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while (i < utftext.length) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i + 1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i + 1);
				c3 = utftext.charCodeAt(i + 2);
				string += String.fromCharCode(((c & 15) << 12)
						| ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

/*
 * 单片提交页面
 */
function addTab_backup() {
	//var Request = new Object();
	//Request = GetRequest();
	//var b = new Base64();
	// 转载本地存储到页面表单
	 alert(localData.getItem("title"));
	$("#title").val(localData.getItem("title"));
	//$("#title").val(b.decode(Request['title']));

	$("#tag").val(localData.getItem("tag"));
	//$("#tag").val(b.decode(Request['tag']));
	$("#intro").val(localData.getItem("intro"));
	//$("#intro").val(b.decode(Request['intro']));

	cat_id_select = document.getElementById("cat_id");
	set_cat_id = localData.getItem("set_cat_id");
	for ( var i = 0; i < cat_id_select.options.length; i++) {
		if (cat_id_select.options[i].value == set_cat_id) {
			cat_id_select.options[i].selected = true;
		}
	}
	getrepeat();
	repeat_id_select = document.getElementById("repeat_id");
	for ( var i = 0; i < repeat_id_select.options.length; i++) {
		if (repeat_id_select.options[i].value == localData
				.getItem("set_repeat_id")) {
			repeat_id_select.options[i].selected = true;
		}
	}
	getpartner();
	partner_id_select = document.getElementById("partner_id");
	for ( var i = 0; i < partner_id_select.options.length; i++) {
		if (partner_id_select.options[i].value == localData
				.getItem("set_partner_id")) {
			partner_id_select.options[i].selected = true;
		}
	}
	cover_checkbox = document.getElementsByName("cover");
	// var coverAry = JSON.parse(localData.getItem("set_cover"));
	if (localData.getItem("set_cover") != null) {
		var coverAry = localData.getItem("set_cover").split(",");
		// alert("test12");
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAry.length; j++) {
				if (cover_checkbox[i].value == coverAry[j]) {
					cover_checkbox[i].checked = true;
				}
			}

		}
	}
	// $("#cover").val(localData.getItem("set_cover"));
	$("#album_id").val(localData.getItem("set_album_id"));
	//$("#album_id").val(b.decode(Request['album_id']));
	$("#special_id").val(localData.getItem("set_special_id"));
	//$("#special_id").val(b.decode(Request['special_id']));

	$("#url").val(localData.getItem("url"));
	//$("#url").val(b.decode(Request['url']));
	$("#sendtype").val(localData.getItem("sendtype"));
	//$("#sendtype").val(b.decode(Request['sendtype']));
	$("#format").val(localData.getItem("format"));
	//$("#format").val(b.decode(Request['format']));

}


/*
 * 单片提交页面
 */
function addTab() {
	var Request = new Object();
	Request = GetRequest();
	var b = new Base64();
	// 转载本地存储到页面表单
	 //alert(localData.getItem("title"));
	//$("#title").val(localData.getItem("title"));
	//alert(Request['title']);
	//alert(b.decode(Request['title']));
	$("#title").val(b.decode(Request['title']));

	//$("#tag").val(localData.getItem("tag"));
	$("#tag").val(b.decode(Request['tag']));
	//$("#intro").val(localData.getItem("intro"));
	$("#intro").val(b.decode(Request['intro']));

	getcat();
	//getSetting();
	cat_id_select = document.getElementById("cat_id");
	set_cat_id = localData.getItem("set_cat_id");
	
	for ( var i = 0; i < cat_id_select.options.length; i++) {
		if (cat_id_select.options[i].value == set_cat_id) {
			cat_id_select.options[i].selected = true;
		}
	}
	getrepeat();
	repeat_id_select = document.getElementById("repeat_id");
	for ( var i = 0; i < repeat_id_select.options.length; i++) {
		if (repeat_id_select.options[i].value == localData
				.getItem("set_repeat_id")) {
			repeat_id_select.options[i].selected = true;
		}
	}
	getpartner();
	partner_id_select = document.getElementById("partner_id");
	for ( var i = 0; i < partner_id_select.options.length; i++) {
		if (partner_id_select.options[i].value == localData
				.getItem("set_partner_id")) {
			partner_id_select.options[i].selected = true;
		}
	}
	cover_checkbox = document.getElementsByName("cover");
	 var set_cover = localData.getItem("set_cover");
	if (set_cover != null) {
		var coverStr = set_cover.replace(/\"/g,"").replace("[","").replace("]","");
		var coverAry = coverStr.split(",");
		// alert("test12");
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAry.length; j++) {
				cover_checkbox[i].checked = false;
			}
		}
		
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAry.length; j++) {
				if (cover_checkbox[i].value == coverAry[j]) {
					cover_checkbox[i].checked = true;
				}
			}

		}
	}
	// $("#cover").val(localData.getItem("set_cover"));
	$("#album_id").val(localData.getItem("set_album_id"));
	//$("#album_id").val(b.decode(Request['album_id']));
	$("#special_id").val(localData.getItem("set_special_id"));
	//$("#special_id").val(b.decode(Request['special_id']));

	//$("#url").val(localData.getItem("url"));
	$("#url").val(b.decode(Request['url']));
	$("#sendtype").val(localData.getItem("sendtype"));
	//$("#sendtype").val(b.decode(Request['sendtype']));
	$("#format").val(localData.getItem("format"));
	//$("#format").val(b.decode(Request['format']));

}

/*
 * 发布设置页面
 */
function settingTab() {
	// 转载本地存储到页面表单
	getcat();
	//getSetting();
	cat_id_select = document.getElementById("set_cat_id");
	for ( var i = 0; i < cat_id_select.options.length; i++) {
		if (cat_id_select.options[i].value == localData.getItem("set_cat_id")) {
			cat_id_select.options[i].selected = true;
		}
	}
	getrepeat();
	repeat_id_select = document.getElementById("set_repeat_id");
	for ( var i = 0; i < repeat_id_select.options.length; i++) {
		if (repeat_id_select.options[i].value == localData
				.getItem("set_repeat_id")) {
			repeat_id_select.options[i].selected = true;
		}
	}
	getpartner();
	partner_id_select = document.getElementById("set_partner_id");
	for ( var i = 0; i < partner_id_select.options.length; i++) {
		if (partner_id_select.options[i].value == localData
				.getItem("set_partner_id")) {
			partner_id_select.options[i].selected = true;
		}
	}
	cover_checkbox = document.getElementsByName("set_cover");
	var set_cover = localData.getItem("set_cover");
	if (set_cover != null) {
		//var coverAryJson = JSON.parse(coverAry);
		var coverStr = set_cover.replace(/\"/g,"").replace("[","").replace("]","");
		//alert(coverStr);
		var coverAry = coverStr.split(",");
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAry.length; j++) {
				if (cover_checkbox[i].value == coverAry[j]) {
					//alert(coverAryJson[j]);
					cover_checkbox[i].checked = true;
				}
			}

		}
	}

	$("#set_album_id").val(localData.getItem("set_album_id"));
	$("#set_special_id").val(localData.getItem("set_special_id"));
}

/*
 * 发布设置
 */
function setting() {
	var album_id = $("#set_album_id").val();
	var special_id = $("#set_special_id").val();
	if( (isNaN(special_id) && special_id !='') || ( isNaN(album_id)  && album_id !='' )  ){
		alert("请填写正确的专辑id和专题id！");
		return;
	}
	// 表单设置到本地存储
	// 发送给扩展模块
	cat_id_select = document.getElementById("set_cat_id");
	var cat_id = cat_id_select.options[cat_id_select.options.selectedIndex].value

	repeat_id_select = document.getElementById("set_repeat_id");
	var repeat_id = repeat_id_select.options[repeat_id_select.options.selectedIndex].value

	partner_id_select = document.getElementById("set_partner_id");
	var partner_id = partner_id_select.options[partner_id_select.options.selectedIndex].value
	
	if(cat_id == '' ||cat_id ==0){alert("分类不能为空！");return;}
	if(repeat_id ==''){alert("马甲不能为空！");return;}
	if(partner_id == ''){alert("合作伙伴不能为空！");return;}
	
	var coverAry = new Array();
	cover_checkbox = document.getElementsByName("set_cover");
	for ( var i = 0; i < cover_checkbox.length; i++) {
		if (cover_checkbox[i].checked) {
			coverAry.push(cover_checkbox[i].value);
		}
	}
	var partner_id = partner_id_select.options[partner_id_select.options.selectedIndex].value

	/*
	localData.setItem("set_cat_id", cat_id);
	localData.setItem("set_repeat_id", repeat_id);
	localData.setItem("set_partner_id", partner_id);
	localData.setItem("set_cover", eval(coverAry));
	localData.setItem("set_album_id", $("#set_album_id").val());
	localData.setItem("set_special_id", $("#set_special_id").val());
	alert("设置成功！");
	*/
	
	var str = "";
	str += "cat_id=" + cat_id;
	str += "&repeat_id=" + repeat_id;
	str += "&partner_id=" + partner_id;
	str += "&album_id=" + $("#set_album_id").val();
	str += "&special_id=" + $("#set_special_id").val();
	str += "&cover=" + eval(coverAry);
	var calc = document.getElementById('Calc');
	var result = calc.POST("http://api.cntv.cn/client/setconfig", str);
	 // alert(result);
	// 返回-1是其他错误; 返回-2是C:\\WINDOWS\\system32\\drivers\\etc\\hosts不可读;
	// 返回-3是api.cntv.cn不通
	if (result == 200) {
		 // alert(calc.GetResponse());
		// var json = eval('(' + calc.GetResponse() + ')');
		// var json = calc.GetResponse().parseJSON();
		var myJson = calc.GetResponse();
		if(myJson != ""){
			var json = eval("(" + myJson + ")");
			if(json.ret == 'succ'){
				alert("设置成功！");
			}else{
				alert("设置失败！");
			}
		}else{
			alert("设置失败！");
		}

	}
	
}




/*
 * 取得设置信息
 */
function getSetting() {
	var str = "";
	//xmlhttp.onreadystatechange = getSettingCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getconfig?format=json&t=" + new Date().getTime(), false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
	getSettingCallback();
	
}
/*
 * 取得设置信息回调
 */
function getSettingCallback() {
	//alert("getSettingCallback");
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//var json = JSON.parse(xmlhttp.responseText);
		var json = eval("("+xmlhttp.responseText+")");
		//alert(json.status);
		if (json.ret == 'succ') {
			localData.setItem("set_cat_id", json.data.cat_id);
			localData.setItem("set_repeat_id",  json.data.repeat_id);
			localData.setItem("set_partner_id",  json.data.partner_id);
			localData.setItem("set_cover", json.data.cover);
			localData.setItem("set_album_id", json.data.album_id);
			localData.setItem("set_special_id", json.data.special_id);
			//return;
		} else {

		}
	}
}




/*
 * 批量添加页面
 */
function batchaddTab_new() {
	var tab = document.getElementById("batchlist");
	// 如果是ie
	if (document.all) {
		var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = eval("(" + localData.getItem("Arraytitle") + ")");
		var Aurl = eval("(" + localData.getItem("Arrayurl") + ")");
		if (Aurl != null && Arraytitle != null) {
			for ( var i = 0; i < Aurl.length; ++i) {
				table += "<tr>";
				table += "<td width=\"26\"><input  class=\"checkitem\"  type=\"checkbox\" value=\""
						+ i + "\"/ id=\"id_" + i + "\"></td>";
				table += "<td><input   type=\"hidden\" value=\""
						+ Arraytitle[i] + "\"/ id=\"title_" + i + "\">"
						+ Arraytitle[i] + "</td>";
				table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + Aurl[i]
						+ "\"/ id=\"url_" + i + "\">" + Aurl[i] + "</td>";
				table += "</tr>";
				/*
				 * var tab = document.getElementById("hmhm"); var row =
				 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
				 * row.insertCell(-1); var cell2 = row.insertCell(-1); var cell3 =
				 * row.insertCell(-1); cell1.innerHTML = "<td><input
				 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
				 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
				 * Aurl[i] + "</td>"; num++;
				 */

			}
			table += "</table>";
			var cat_id = localData.getItem("set_cat_id");
			var repeat_id = localData.getItem("set_repeat_id");
			var partner_id = localData.getItem("set_partner_id");
			var album_id = localData.getItem("set_album_id");
			var special_id = localData.getItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.innerText = "共" + Aurl.length + "条信息"; // alert(Aurl.length);
		}
		// 其他浏览器
	} else {
		var table = "<table class=\"tbl lstb\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = eval("(" + localData.getItem("Arraytitle") + ")");
		var Aurl = eval("(" + localData.getItem("Arrayurl") + ")");
		if (Aurl != null && Arraytitle != null) {
			for ( var i = 0; i < Aurl.length; ++i) {
				table += "<tr>";
				table += "<td width=\"26\"><input  class=\"checkitem\"  type=\"checkbox\" value=\""
						+ i + "\"/ id=\"id_" + i + "\"></td>";
				table += "<td><input   type=\"hidden\" value=\""
						+ Arraytitle[i] + "\"/ id=\"title_" + i + "\">"
						+ Arraytitle[i] + "</td>";
				table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + Aurl[i]
						+ "\"/ id=\"url_" + i + "\">" + Aurl[i] + "</td>";
				table += "</tr>";
				/*
				 * var tab = document.getElementById("hmhm"); var row =
				 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
				 * row.insertCell(-1); var cell2 = row.insertCell(-1); var cell3 =
				 * row.insertCell(-1); cell1.innerHTML = "<td><input
				 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
				 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
				 * Aurl[i] + "</td>";
				 */
			}
			table += "</table>";
			var cat_id = localData.getItem("set_cat_id");
			var repeat_id = localData.getItem("set_repeat_id");
			var partner_id = localData.getItem("set_partner_id");
			var album_id = localData.getItem("set_album_id");
			var special_id = localData.getItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.textContent = "共" + Aurl.length + "条信息";// alert(Aurl.length)
		}

	}
}
/*
 * 过滤url
 */
function filterBykey_new() {
	var tab = document.getElementById("batchlist");
	var filterKey = document.getElementById("filterKey").value;
	// 如果是ie
	if (document.all) {
		var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = eval("(" + localData.getItem("Arraytitle") + ")");
		var Aurl = eval("(" + localData.getItem("Arrayurl") + ")");
		var listIndex = 0;
		if (Aurl != null && Arraytitle != null) {
			for ( var i = 0; i < Aurl.length; ++i) {
				if (Aurl[i].indexOf(filterKey) >= 0) {
					table += "<tr>";
					table += "<td width=\"26\"><input  class=\"checkitem\"  type=\"checkbox\" value=\""
							+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
					table += "<td><input   type=\"hidden\" value=\""
							+ Arraytitle[i] + "\"/ id=\"title_" + listIndex
							+ "\">" + Arraytitle[i] + "</td>";
					table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + Aurl[i]
							+ "\"/ id=\"url_" + listIndex + "\">" + Aurl[i]
							+ "</td>";
					table += "</tr>";
					/*
					 * var tab = document.getElementById("hmhm"); var row =
					 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
					 * row.insertCell(-1); var cell2 = row.insertCell(-1); var
					 * cell3 = row.insertCell(-1); cell1.innerHTML = "<td><input
					 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
					 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
					 * Aurl[i] + "</td>"; num++;
					 */
					listIndex++;
				}

			}
			table += "</table>";
			var cat_id = localData.getItem("set_cat_id");
			var repeat_id = localData.getItem("set_repeat_id");
			var partner_id = localData.getItem("set_partner_id");
			var album_id = localData.getItem("set_album_id");
			var special_id = localData.getItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.innerText = "共" + Aurl.length + "条信息"; // alert(Aurl.length);
		}
		// 其他浏览器
	} else {
		var table = "<table class=\"tbl lstb\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = eval('('+localData.getItem("Arraytitle")+')');
		var Aurl = eval('('+localData.getItem("Arrayurl")+')');
		var listIndex = 0;
		if (Aurl != null && Arraytitle != null) {
			for ( var i = 0; i < Aurl.length; ++i) {
				if (Aurl[i].indexOf(filterKey) >= 0) {
					table += "<tr>";
					table += "<td width=\"26\"><input  class=\"checkitem\"  type=\"checkbox\" value=\""
							+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
					table += "<td><input   type=\"hidden\" value=\""
							+ Arraytitle[i] + "\"/ id=\"title_" + listIndex + "\">"
							+ Arraytitle[i] + "</td>";
					table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + Aurl[i]
							+ "\"/ id=\"url_" + listIndex + "\">" + Aurl[i] + "</td>";
					table += "</tr>";
					/*
					 * var tab = document.getElementById("hmhm"); var row =
					 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
					 * row.insertCell(-1); var cell2 = row.insertCell(-1); var
					 * cell3 = row.insertCell(-1); cell1.innerHTML = "<td><input
					 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
					 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
					 * Aurl[i] + "</td>";
					 */
					listIndex++;
				}
			}
			table += "</table>";
			var cat_id = localData.getItem("set_cat_id");
			var repeat_id = localData.getItem("set_repeat_id");
			var partner_id = localData.getItem("set_partner_id");
			var album_id = localData.getItem("set_album_id");
			var special_id = localData.getItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.textContent = "共" + Aurl.length + "条信息";// alert(Aurl.length)
		}
	}
}




/*
 * 批量添加页面
 */
function batchaddTab() {
	// alert("test1");
	//getSetting();
	var sHref = document.location.href
	var args = sHref.split("?");
	if (args[0] == sHref) /* 参数为空 */
	{
		var hmnum = document.getElementById("hmnum");
		hmnum.innerText = ""; // alert(Aurl.length);
		return; /* 无需做任何处理 */
	}
	var str = args[1];
	args = str.split("&");
	var b = new Base64();
	// alert("test2");
	var tab = document.getElementById("batchlist");
	// 如果是ie
	var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
	table += "<tr>";
	table += "<th>选择</th>";
	table += "<th>标题</th>";
	table += "<th>url</th>";
	table += "</tr>";
	// alert("test3");
	var listIndex = 0;
	for ( var i = 0; i < args.length; i++) {
		// alert("test31");
		str = args[i];
		 //alert("test311");
		 //alert(str);
		var arg = str.split("|");
		 //alert("test312");
		if (arg.length <= 1){
			continue;
		}else{
			// alert("test313");
			 //addd(b.decode(arg[0]), b.decode(arg[1]));
			 //alert("test32");
			table += "<tr>";
			table += "<td width=\"26\"><input name=\"checkitem\" class=\"checkitem\"  type=\"checkbox\" value=\""
					+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
			table += "<td><input  type=\"hidden\" value=\"" + b.decode(arg[0])
					+ "\"/ id=\"title_" + listIndex + "\">" + b.decode(arg[0]) + "</td>";
			table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + b.decode(arg[1])
					+ "\"/ id=\"url_" + listIndex + "\">" 
					+ "<div style=\"width:100px;word-break:break-all;\">"
					+ b.decode(arg[1])  + "</div>"
					+ "</td>";
			table += "</tr>";
			 //alert("test33");
			listIndex++;
		}

	}
	table += "</table>";
	// alert("test34");
	var cat_id = localData.getItem("set_cat_id");
	var repeat_id = localData.getItem("set_repeat_id");
	var partner_id = localData.getItem("set_partner_id");
	var album_id = localData.getItem("set_album_id");
	var special_id = localData.getItem("set_special_id");
	var set_cover = localData.getItem("set_cover");
	var cover = set_cover;
	if(set_cover) cover = set_cover.replace(/\"/g,"").replace("[","").replace("]","");
	// alert("test35");
	var setDiv = "<div style='display:none;'>";
	setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
			+ cat_id + "\" />";
	setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
			+ repeat_id + "\" />";
	setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
			+ partner_id + "\" />";
	setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
			+ album_id + "\" />";
	setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
			+ special_id + "\" />";
	setDiv += "<input type=\"text\" id=\"cover\" name=\"cover\" value=\""
		+ cover + "\" />";
	setDiv += "</div>";
	tab.innerHTML = table + setDiv;
	// alert("test36");
	var hmnum = document.getElementById("hmnum");
	hmnum.innerText = "共" + listIndex + "条信息"; // alert(Aurl.length);
	// alert("test4");
}
/*
 * 过滤url
 */
function filterBykey() {
	// =============================
	var filterKey = document.getElementById("filterKey").value;
	// alert("test1");
	var sHref = document.location.href
	var args = sHref.split("?");
	if (args[0] == sHref) /* 参数为空 */
	{
		return; /* 无需做任何处理 */
	}
	var str = args[1];
	args = str.split("&");
	var b = new Base64();
	// alert("test2");
	var tab = document.getElementById("batchlist");
	// 如果是ie
	var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
	table += "<tr>";
	table += "<th>选择</th>";
	table += "<th>标题</th>";
	table += "<th>url</th>";
	table += "</tr>";
	// alert("test3");
	var listIndex = 0;
	for ( var i = 0; i < args.length; i++) {
		// alert("test31");
		str = args[i];
		// alert("test311");
		var arg = str.split("|");
		// alert("test312");
		if (arg.length <= 1)
			continue;
		// alert("test313");
		// addd(b.decode(arg[0]), b.decode(arg[1]));
		// alert("test32");
		if (b.decode(arg[1]).indexOf(filterKey) >= 0) {
			table += "<tr>";
			table += "<td width=\"26\"><input name=\"checkitem\" class=\"checkitem\"  type=\"checkbox\" value=\""
					+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
			table += "<td><input   type=\"hidden\" value=\"" + b.decode(arg[0])
					+ "\"/ id=\"title_" + listIndex + "\">" + b.decode(arg[0]) + "</td>";
			table += "<td width=\"100\"><input   type=\"hidden\" value=\"" + b.decode(arg[1])
					+ "\"/ id=\"url_" + listIndex + "\">" 
					+ "<div style=\"width:100px;word-break:break-all;\">"
					+ b.decode(arg[1]) + "</div>"
					+ "</td>";
			table += "</tr>";
			// alert("test33");
			listIndex++;
		}
	}
	table += "</table>";
	// alert("test34");
	var cat_id = localData.getItem("set_cat_id");
	var repeat_id = localData.getItem("set_repeat_id");
	var partner_id = localData.getItem("set_partner_id");
	var album_id = localData.getItem("set_album_id");
	var special_id = localData.getItem("set_special_id");
	var set_cover = localData.getItem("set_cover");
	var cover = set_cover;
	if(set_cover) cover = set_cover.replace(/\"/g,"").replace("[","").replace("]","");
	// alert("test35");
	var setDiv = "<div style='display:none;'>";
	setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
			+ cat_id + "\" />";
	setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
			+ repeat_id + "\" />";
	setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
			+ partner_id + "\" />";
	setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
			+ album_id + "\" />";
	setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
			+ special_id + "\" />";
	setDiv += "<input type=\"text\" id=\"cover\" name=\"cover\" value=\""
		+ cover + "\" />";
	setDiv += "</div>";
	tab.innerHTML = table + setDiv;
	// alert("test36");
	var hmnum = document.getElementById("hmnum");
	hmnum.innerText = "共" + (listIndex) + "条信息"; // alert(Aurl.length);
	// alert("test4");

}

/*
 * 取得用户信息
 */
function getuserinfo() {
	// alert("getuserinfo");
	
    var calc = document.getElementById('Calc');
    result = calc.GET("http://api.cntv.cn/client/getuserinfo");
     //alert(result); //返回-1是其他错误;
	// 返回-2是C:\\WINDOWS\\system32\\drivers\\etc\\hosts不可读; 返回-3是api.cntv.cn不通
    if(result==200) {
         //alert(calc.GetResponse());
        var username = '';
        // var json = JSON.parse(xmlhttp.responseText);
        var json = eval('(' + calc.GetResponse() + ')');
        //var json = JSON.parse(calc.GetResponse());
         //username = "123";
        username = json.username;
        // alert(username);
        
		if (typeof (username) == "undefined" || username == "") {
			$("#tabs_div").hide();
			createCode();
			$("#login_div").show();
			// alert("userinfo faild");
		} else {
			$("#login_div").hide();
			$("#uname").text(username);
			$("#tabs_div").show();
			var hash = window.location.hash;
			if( hash != "" ){
				selectTabs(window.location.hash);
			}else{
				selectTabs("#tabs-1");
			}
			
			
			// alert("userinfo succ");
		}
    }

}
/*
 * 取得用户信息回调
 */
function getuserinfoCallback() {
	// alert("getuserinfoCallback");
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		// alert("getuserinfoCallback"+xmlhttp.responseText);
		var username = '';
		// var json = JSON.parse(xmlhttp.responseText);
		var json = eval("(" + xmlhttp.responseText + ")");
		username = json.username;
		// username = "12345";
		// alert(username);
		// alert(typeof (username));
		if (typeof (username) == "undefined" || username == "") {
			$("#tabs_div").hide();
			createCode();
			$("#login_div").show();
			// alert("userinfo faild");
		} else {
			$("#login_div").hide();
			$("#uname").text(username);
			$("#tabs_div").show();
			var hash = window.location.hash;
			if( hash != "" ){
				selectTabs(window.location.hash);
			}else{
				selectTabs("#tabs-1");
			}
			
			
			
			// alert("userinfo succ");
		}
	}
}


/*
 * 初始化
 */
function initPage() {
	// 判断是否登录
	// alert("initPage");
	// alert(localData.getItem("title"));
	$("#tabs_div").hide();
	$("#login_div").hide();
	getuserinfo();
}

/*
 * tabs切换
 */
function selectTabs(tabIndex) {
	$("#tabs-1").hide();
	$("#tabs-2").hide();
	$("#tabs-3").hide();
	$("#tabs-4").hide();

	$("#tabsLi-1").removeClass("cur");
	$("#tabsLi-2").removeClass("cur");
	$("#tabsLi-3").removeClass("cur");
	$("#tabsLi-4").removeClass("cur");

	// alert(tabIndex);
	if (tabIndex == '#tabs-1') {
		// alert(tabIndex);
		getSetting();
		$("#tabs-1").show();
		$("#tabsLi-1").addClass("cur");
		addTab();
	}
	if (tabIndex == '#tabs-2') {
		// alert(tabIndex);
		getSetting();
		$("#tabs-2").show();
		$("#tabsLi-2").addClass("cur");
		batchaddTab();
	}
	if (tabIndex == '#tabs-3') {
		// alert(tabIndex);
		getSetting();
		$("#tabs-3").show();
		$("#tabsLi-3").addClass("cur");
		settingTab();
	}
	if (tabIndex == '#tabs-4') {
		// alert(tabIndex);
		$("#tabs-4").show();
		$("#tabsLi-4").addClass("cur");
		var Request = new Object();
		Request = GetRequest();
		page = Request['page'];
		if (!page) {
			page = 1;
		}
		videolist(page);
	}
}
/*
 * 入口程序
 */
$(document).ready(function() {
	initPage();
});

